package com.gitee.wsl.time.schedule

import com.gitee.wsl.ext.base.currentTime
import kotlin.time.Instant
import kotlinx.datetime.TimeZone
import kotlin.time.ExperimentalTime

@OptIn(ExperimentalTime::class)
interface TimeScheduler: Comparable<TimeScheduler> {
    /**
     * Calculates the next occurrence based on the creation time and the current time.
     *
     * @param createdAt Instant object when the schedule was first created
     * @param zoneId the zone for which to calculate the schedule
     * @return Instant of the next occurrence.
     */
    fun next(createdAt: Instant, zoneId: TimeZone = TimeZone.UTC): Result<Instant> {
        return next(createdAt, currentTime, zoneId)
    }

    /**
     * Calculates the next occurrence based on the creation time and the provided base time.
     *
     * @param createdAtInstant Instant object when the schedule was first created
     * @param currentInstant Instant object used to calculate next occurrence (normally Instant.now()).
     * @param zoneId the zone for which to calculate the schedule
     * @return Instant of the next occurrence.
     */
    fun next(
        createdAtInstant: Instant,
        currentInstant: Instant,
        zoneId: TimeZone = TimeZone.UTC,
    ): Result<Instant>

    fun validateSchedule(){}

    companion object
}